﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace testgame
{/// <summary>
/// 发射筒类
/// </summary>
    class LaunchCanister
    {


        //绘制飞机

        private const int step = 10;//处理飞机移动速度
        private const int LaunchCanisterWidth = 100;//绘制飞机宽度
        private int _gameWidth=600;//将游戏区域大小引入
        public static int LCx;//坐标x
        public static int LCy;//坐标y
        public static int health = 100; //血量
        public static Image LCImage = Properties.Resources.飞机;//我方飞机图片
        static List<Keys> keys = new List<Keys>();//键盘键列表，用于控制飞机移动
        public static Image gameOver = Properties.Resources.gameover;//声明游戏结束
        public static int score = 0;      //得分

        //处理飞机坐标
        public LaunchCanister(int gameWidth)
        {
            _gameWidth = gameWidth;
            LCx = (_gameWidth - LaunchCanisterWidth) / 2;
            LCy = 300;

        }

        //画飞机
        public static void LCShow(Graphics g)
        {
            if (health > 0)
            {
                g.DrawImage(LCImage, LCx, LCy, 100, 100);
            }
            else if (health == 0)
            {
                //g.DrawImage(gameOver, 200, 100, 200, 200);
                g.DrawImage(LCImage, 0, -900, 100, 100);
            }
           
        }
        //处理键盘

        /// <summary>
        /// 松开键盘键
        /// </summary>
        /// <param name="key"></param>
        public static void Keyup(Keys key)
        {
            keys.Remove(key);
        }

        /// <summary>
        /// 按下键盘键
        /// </summary>
        /// <param name="key"></param>
        public static void Keydown(Keys key)
        {
            if (!keys.Contains(key))
            {
                keys.Add(key);
            }
        }

        /// <summary>
        /// 判断按键是否被按下
        /// </summary>
        /// <param name="key"></param>
        /// <returns>是则返回true  不是则返回false</returns>
        public static bool IsKeyDown(Keys key)
        {
            return keys.Contains(key);
        }

        public static void LCMove()
        {
            if (IsKeyDown(Keys.A))
            {
                LCImage = Properties.Resources.飞机;
                
                //防止左出界
                if ((LCx  - step) < 0)
                    LCx  = 0;
                 LCx -= step;


            }

            if (IsKeyDown(Keys.D))
            {
                LCImage = Properties.Resources.飞机;

                //防止右出界
                if ((LCx + step + LaunchCanisterWidth) > 600)
                    LCx  = 600- LaunchCanisterWidth;
                LCx += step;
            }
            
        }
    }
}
